package com.study.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.apache.commons.dbutils.QueryRunner;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.InputStream;
import java.util.Properties;

public class DruidUtils {
    public static DataSource getDataSource(){
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("druid.properties");
        Properties pro = new Properties();
        DataSource ds = null;
        try {
            pro.load(is);
            ds = DruidDataSourceFactory.createDataSource(pro);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ds;
    }

    public static QueryRunner getQueryRunner(){
        QueryRunner qr = new QueryRunner(getDataSource());
        return qr;
    }
    @Test
    public void getQ(){
        System.out.println("getQueryRunner() = " + getQueryRunner());
    }

}
